package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.domain.PmsAttrAttrgroupRelation;
import com.sky.service.PmsAttrAttrgroupRelationService;
import com.sky.mapper.PmsAttrAttrgroupRelationMapper;
import com.sky.vo.param.PmsAttrAttrGroupRelationVO;
import com.sky.vo.param.PmsAttrVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【pms_attr_attrgroup_relation(属性&属性分组关联)】的数据库操作Service实现
* @createDate 2024-06-30 16:46:42
*/
@Service
public class PmsAttrAttrgroupRelationServiceImpl extends ServiceImpl<PmsAttrAttrgroupRelationMapper, PmsAttrAttrgroupRelation> implements PmsAttrAttrgroupRelationService{

    @Override
    public List<PmsAttrAttrgroupRelation> listByGroupId(Long groupId) {
        List<PmsAttrAttrgroupRelation> relationList = baseMapper.selectList(new LambdaQueryWrapper<PmsAttrAttrgroupRelation>().eq(PmsAttrAttrgroupRelation::getAttrGroupId, groupId));
        return relationList;
    }

    /**
     * 删除属性分组关联
     * @param voList 属性分组关联
     * @return 是否删除成功
     */
    @Override
    public boolean deleteGroupRelation(List<PmsAttrAttrGroupRelationVO> voList) {
        for (PmsAttrAttrGroupRelationVO vo : voList) {
            baseMapper.delete(new LambdaQueryWrapper<PmsAttrAttrgroupRelation>()
                    .eq(PmsAttrAttrgroupRelation::getAttrId, vo.getAttrId())
                    .eq(PmsAttrAttrgroupRelation::getAttrGroupId, vo.getAttrGroupId()));
        }
        return true;
    }

    /**
     * 添加属性分组关联
     * @param voList 属性分组关联
     * @return 是否添加成功
     */
    @Override
    public boolean addGroupRelation(List<PmsAttrAttrGroupRelationVO> voList) {
        for (PmsAttrAttrGroupRelationVO vo : voList) {
            PmsAttrAttrgroupRelation pmsAttrAttrgroupRelation = new PmsAttrAttrgroupRelation();
            BeanUtils.copyProperties(vo, pmsAttrAttrgroupRelation);
            baseMapper.insert(pmsAttrAttrgroupRelation);
        }
        return false;
    }
}




